package core.command;

import java.util.ArrayList;

import core.Drawing;
import core.MyCursor;
import core.Point2D;
import core.Stroke;

public class TransformStrokesCommand extends AbstractCommand {

	private ArrayList<StrokesTransformation> transformations = new ArrayList<StrokesTransformation>();
	
	public TransformStrokesCommand(
			Drawing drawing,
			ArrayList<Stroke> strokes,
			int cursorId,
			MyCursor cursor0,
			MyCursor cursor1,
			Point2D cursor0CurrentPosition,
			Point2D cursor0PreviousPosition,
			Point2D cursor1CurrentPosition,
			Point2D cursor1PreviousPosition
	) {	
		super(drawing);
		StrokesTransformation transformation = new StrokesTransformation(
				strokes,
				cursorId,
				cursor0,
				cursor1,
				cursor0CurrentPosition,
				cursor0PreviousPosition,
				cursor1CurrentPosition,
				cursor1PreviousPosition
		);
		this.transformations.add(transformation);
	}
	
	@Override
	public void execute() {
		for (int i = 0; i < this.transformations.size(); ++i) {
			this.transformations.get(i).execute();
		}
		drawing.markBoundingRectangleDirty();
	}

	@Override
	public void undo() {
		for (int i = this.transformations.size()-1; i >= 0; --i) {
			this.transformations.get(i).undo();
		}
		drawing.markBoundingRectangleDirty();
	}

	public ArrayList<StrokesTransformation> getTransformations() {
		return this.transformations;
	}
	
	public void addTransformation(StrokesTransformation transformation) {
		this.transformations.add(transformation);
	}
}
